/*******************************************************************************
 * Copyright (c) 2023. 山东新北洋信息技术股份有限公司 保留所有权利。
 *
 ******************************************************************************/

package online.xuping.center.account;

import online.xuping.thousandsOfWorlds.common.constants.CommonErrorCodeHelper;
import online.xuping.thousandsOfWorlds.common.constants.ErrorTypeCodeEnum;
import online.xuping.thousandsOfWorlds.common.constants.ModelCodeEnum;
import online.xuping.thousandsOfWorlds.common.constants.WarehouseBusinessCodeEnum;

/**
 * 入参错误码.
 */
public enum AccountErrorCodeEnum implements CommonErrorCodeHelper {

    ACCOUNT_TYPE_NULL_ERROR("类型数据异常", "1", ErrorTypeCodeEnum.SYSTEM_ERROR),
    ACCOUNT_TYPE_SETTING_ERROR("账户配置错误", "2", ErrorTypeCodeEnum.SYSTEM_ERROR),


    ;

    /**
     * 错误码
     */
    private final String code;
    /**
     * 错误信息
     */
    private final String msg;

    /**
     * 构造方法
     *
     * @param msg               错误信息
     * @param code              code
     * @param errorTypeCodeEnum 类型枚举
     */
    AccountErrorCodeEnum(String msg, String code, ErrorTypeCodeEnum errorTypeCodeEnum) {
        this.code = ModelCodeEnum.WAREHOUSE.getCode() + errorTypeCodeEnum.getCode() +
                WarehouseBusinessCodeEnum.OTHER.getCode() + code;
        this.msg = msg;
    }

    /**
     * @param message      .
     * @param defaultValue .
     * @return .
     */
    public static String findCodeByMessage(String message, String defaultValue) {

        if (defaultValue == null) {
            defaultValue = Constants.OTHER1;
        }
        String defCode = "111111";
        if (message == null) {
            return defCode;
        }
        for (AccountErrorCodeEnum codeEnum : AccountErrorCodeEnum.values()) {
            if (message.equals(codeEnum.msg)) {
                return codeEnum.code;
            }
            if (defaultValue.equals(codeEnum.msg)) {
                defCode = codeEnum.code;
            }
        }

        return defCode;
    }

    /**
     * @param message .
     * @return .
     */
    public static String findCodeByMessage(String message) {
        return findCodeByMessage(message, Constants.OTHER1);
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    private static class Constants {
        public static final String OTHER1 = "OTHER";
    }
}
